import {defineStore} from 'pinia'

interface stateCountType {
    count: number
}

const useCountStore = defineStore('count', {
    state: (): stateCountType => {
        return {
            count: 1
        }
    },
    getters: {
        double: (state): number => {
            return state.count * 2
        }
    },
    actions: {
        // 累加
        increment() {
            this.count++
        },
        // 累加 n
        incrementN(n: number) {
            this.count += n
        },
        // 累加 n
        incrementNM(n: number, m: number) {
            this.count += n + m
        },
        asyncIncrementN(n: number) {
            setTimeout(() => {
                this.count += n
            }, 1000)
        },
    }
})

export default useCountStore